﻿using System.Text.RegularExpressions;
using System.Windows.Controls;
using System.Windows.Data;

namespace HobSoft.SoccerBet2014.Client.Common
{
    using ViewModels;
    public class BookmakerValidationRule : ValidationRule
    {
        Regex hostRegex = new Regex(@"^([a-zA-Z0-9\-]+)(\.?]?[a-zA-Z0-9\-]+)*(:[0-9]+)?$", RegexOptions.Compiled);
        public override ValidationResult Validate(object value, System.Globalization.CultureInfo cultureInfo)
        {
            var vmbm = (value as BindingGroup).Items[0] as Bookmaker;
            if (vmbm == null)
                return ValidationResult.ValidResult;

            if (string.IsNullOrEmpty(vmbm.DefaultHost) || !hostRegex.IsMatch(vmbm.DefaultHost))
                return new ValidationResult(false,"主机域名格式错误。");
            return ValidationResult.ValidResult;
        }
    }
}
